import unittest
from common.base import get_driver
from page.address_page import AddressPage
from page.index_page import IndexPage


class AddressTestCase(unittest.TestCase):

    @classmethod
    def setUpClass(cls) -> None:
        driver = get_driver()
        driver.get('http://localhost:8080/ecshop/index.php')
        cls.address = AddressPage(driver)
        cls.index = IndexPage(driver)

        cls.index.login_shop()
        cls.index.user_address()

    # 添加收货地址用例
    def test_a_add(self):
        self.address.add_address()
        name = self.address.get_name()
        # 通过收货人姓名断言
        self.assertEqual('1号', name, msg='地址添加失败')

    # 修改收货地址用例
    def test_b_alter(self):
        self.address.alter_address()
        name = self.address.get_name()
        # 通过收货人姓名断言
        self.assertEqual('2号', name, msg='地址修改失败')

    # 删除收货地址用例
    def test_c_delete(self):
        self.address.delete_address()
        name = self.address.get_name()
        # 通过收货人姓名断言
        self.assertNotEqual('2号', name, msg='地址删除失败')

    # 添加收货地址，为后续订单模块做准备
    def test_d_add(self):
        self.address.add_address1()
        name = self.address.get_name()
        # 通过收货人姓名断言
        self.assertEqual('第八组', name, msg='地址添加失败')

    @classmethod
    def tearDownClass(cls) -> None:
        cls.address.quit(5)


if __name__ == '__main__':
    unittest.main(verbosity=2)
